using System.Collections;
using WatiN.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using QAHelper.Common;
using System.Windows.Forms;

namespace WatiNTest
{
	[TestClass]
    public class TestActivity: TestBase
    {
        Frame frmMain = null;
        #region Constructor

        public TestActivity(TestCaseStructure testContent, ArrayList headerList)
        {
            testCaseStructure = testContent;
            headerListBase = headerList;            

        }

        #endregion

        #region Test Case NavigateToDesiredActivity

        [TestMethod]

        public void NavigateToDesiredActivity()
        {

            WatDoLogin();
            frmMain = TestManager.browser.Frame(Find.ByName("main"));
            int noOfFields = 0;
            ArrayList tempList = tempTestData;//CommonHelper.GetDataFromDictionary(tempTestData, 0);
            
            string pattern = @"\w\?\w[=\d\&\w[=\d\&\w[=\&\w[=\w";
            

            Frame topFrame = TestManager.browser.Frame(Find.BySrc(new System.Text.RegularExpressions.Regex(pattern)));
            WatiNInputHelper.SetPageInput(topFrame, tempList, out noOfFields, "");
            topFrame.TextField(Find.ByName("strValue")).Focus();

            SendKeys.SendWait("{ENTER}");

            DictionaryEntry dataRow = (DictionaryEntry)tempList[0];
            string activityId = dataRow.Value.ToString().Trim();

            string result = string.Empty;
            string actualResult = "&nbsp;";

            if (frmMain.Link(Find.ByText(activityId)).Exists)
            {
                result = "Pass";
            }
            else
                result = "Fail";
            actualResult = "Activity ID in search appeared: " + frmMain.Link(Find.ByText(activityId)).Exists;

            testCaseStructure = QAHelper.Common.CommonHelper.UpdateTestCaseStructure(result, actualResult, testCaseStructure, scenario);
        }

        #endregion

        #region Perform Login to the DallShare (WatiN)

        public void WatDoLogin()
        {
            Frame frameLogin = TestManager.browser.Frame(Find.ByName("main"));//browser.Frame(WatiN.Core.Find.BySrc("/Global/CommonSite/Login/Login.aspx?Msg=&gotoid=&gotoitem="));

            // Model

            TextField txtUserName = frameLogin.TextField(WatiN.Core.Find.ByName("txtUserName"));

            TextField txtPassword = frameLogin.TextField(WatiN.Core.Find.ByName("txtPassword"));

            WatiN.Core.Button btnLogin = frameLogin.Button(WatiN.Core.Find.ByName("btnLogin1"));

            // Code

            txtUserName.Click();

            txtUserName.TypeText("swp.test");

            txtPassword.TypeText("DellShare01");

            btnLogin.Click();
        }

        #endregion


    }
}